#include "listviewwithtitle.h"
#include "ui_listviewwithtitle.h"
#include <QLabel>
#include "tlistview.h"
ListViewWithTitle::ListViewWithTitle(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ListViewWithTitle)
{
    ui->setupUi(this);
    /*
    QHBoxLayout *l = ui->titleLayout;
    mItems = items;
    for(int i=0,t=items.count();  i<t;  i++)
    {
        QLabel *label = new QLabel(items.at(i).mName,ui->title);
        label->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Preferred);
        label->setAlignment(Qt::AlignHCenter);
        l->addWidget(label,items.at(i).mMaxLen);

        label->setFont(QFont("DejaVu Sans",4));

        mLabelTbl.append(label);
        label->installEventFilter(this);

        if(shortIndex==i)
        {
            mModel->changeShort(mItems.at(i).mRole);
            if(mModel->descShort())
                label->setText(mItems.at(i).mName+"↓");
            else
                label->setText(mItems.at(i).mName+"↑");
        }
    }*/
}

void ListViewWithTitle::setShowItems(const QList<ListViewShowItem> &items)
{
   // mDelegate->setItems(items);
    QHBoxLayout *l = ui->titleLayout;

    for(int i=0;i<mLabelTbl.count();i++)
    {
        delete mLabelTbl.at(i);

    }
    mLabelTbl.clear();
    for(int i=0,t=items.count(); i < t; i++)
    {
        QLabel *label = new QLabel(items.at(i).mName,this);
        label->setAlignment((Qt::Alignment)(items.at(i).mAlign));
        label->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Preferred);
        l->addWidget(label,items.at(i).mMaxLen);
        mLabelTbl.append(label);
    }
    ui->listView->repaint();
}

QLabel *ListViewWithTitle::getLabel(const QString &str)
{
    foreach (QLabel *lab, mLabelTbl) {
        if(lab->text()==str)
            return lab;
    }
    return NULL;
}

TListView *ListViewWithTitle::getListView()
{
    return ui->listView;
}

ListViewWithTitle::~ListViewWithTitle()
{
    delete ui;
}
